%-------------------------------------------------------------------------;
% Figure 5: Annualized Sharpe Ratios: Subsamples;
%   Set a=1 for first subperiod (January 1996 - October 2009); 
%   Set a=2 for second subperiod (December 2004 - December 2022); 
%-------------------------------------------------------------------------;

clear;
clc;
close all;

%Set a;
a=1;

%-------------------;
% Import data;
%-------------------;

filename='Main_data_1996_2022';
[data,txt,raw]=xlsread(filename);

dates=txt(2:end,1);

if a==1
    data=data(1:166,:); %Until including Oct 2009;
else 
    if a==2
        data=data(108:324,:); %December2004 onward;
    end
end

%Index data;
SP_500=data(:,1);         %SP 500 index price level;
Div_m=data(:,2);            %Monthly index dividends;
Div_a=data(:,3);            %Annual index dividends;
SP_ret=data(2:end,4);       %Monthly return on SP 500 index;

%Dividend strip data;
Div_strip_12=data(:,5);     %Price of 12-month dividend strip;
Div_strip_ret=data(2:end,6);%Monthly return on dividend strip strategy;

%Indicated dividends;
Ind_div=data(1:end,7);  

%Bond returns;
Bond_2y=data(2:end,8);      %Monthly return on 2-year Treasury bond;
Bond_10y=data(2:end,9);     %Monthly return on 10-year Treasury bond;

%Fama-French data;
Mkt_Rf=data(2:end,10);      %Market factor;
Rf=data(2:end,11);          %Risk-free rate;

%Define dividend-to-price ratios;
DP_sp=Div_a./SP_500;
DP_strip=Div_a./Div_strip_12;

%Define indicated dividend growthh;
Ind_dg=(Ind_div./Div_a)-1;     

%Take logarithms of all the main variables;
ret_sp=log(SP_ret+1);
ret_strip=log(Div_strip_ret+1);

bond_2y=log(Bond_2y+1);  
bond_10y=log(Bond_10y+1);

mkt_rf=log(Mkt_Rf+1);
rf=log(Rf+1);

dp_sp=log(DP_sp);
dp_strip=log(DP_strip);

ind_dg=log(Ind_dg+1);

%-------------------------------------------------------------------------;
% In excess of the rf;
%-------------------------------------------------------------------------;

ret_sp_ex=ret_sp-rf; 
ret_strip_ex=ret_strip-rf;

SR_mkt=zeros(1,36);
SR_strip=zeros(1,36);

for h=1:36
    
ret_sp_h=filter(ones(h,1),1,ret_sp_ex);
ret_strip_h=filter(ones(h,1),1,ret_strip_ex);

ret_sp_h=ret_sp_h(h:end);
ret_strip_h=ret_strip_h(h:end);

SR_mkt(h)=(mean(ret_sp_h)*100/(h/12))/(std(ret_sp_h)*100/sqrt(h/12));
SR_strip(h)=(mean(ret_strip_h)*100/(h/12))/(std(ret_strip_h)*100/sqrt(h/12));
end

SR_mkt=SR_mkt(1,[1 6 12 18 24 30 36]);
SR_strip=SR_strip(1,[1 6 12 18 24 30 36]);

horizontal_axis=[1,6,12,18,24,30,36];

figure(1)
plot(horizontal_axis,SR_mkt,'-.','LineWidth',1)
hold on;
plot(horizontal_axis,SR_strip,'-','LineWidth',1)
hold on;
legend('Market - rf','Dividend strip - rf')
xlabel('Holding period in months')
ylabel('Annualized Sharpe ratio')
set(gca,'FontSize',8)
axis([1 36 -0.2 0.65]);
xticks([1 6 12 18 24 30 36])

%-------------------------------------------------------------------------;
% In excess of the Treasury returns;
%-------------------------------------------------------------------------;

ret_sp_ex=ret_sp-bond_10y; 
ret_strip_ex=ret_strip-bond_2y;

SR_mkt=zeros(1,36);
SR_strip=zeros(1,36);

for h=1:36
    
ret_sp_h=filter(ones(h,1),1,ret_sp_ex);
ret_strip_h=filter(ones(h,1),1,ret_strip_ex);

ret_sp_h=ret_sp_h(h:end);
ret_strip_h=ret_strip_h(h:end);

SR_mkt(h)=(mean(ret_sp_h)*100/(h/12))/(std(ret_sp_h)*100/sqrt(h/12));
SR_strip(h)=(mean(ret_strip_h)*100/(h/12))/(std(ret_strip_h)*100/sqrt(h/12));
end

SR_mkt=SR_mkt(1,[1 6 12 18 24 30 36]);
SR_strip=SR_strip(1,[1 6 12 18 24 30 36]);

horizontal_axis=[1,6,12,18,24,30,36];

figure(2)
plot(horizontal_axis,SR_mkt,'-.','LineWidth',1)
hold on;
plot(horizontal_axis,SR_strip,'-','LineWidth',1)
hold on;
legend('Market - Treasury 10y','Dividend strip - Treasury 2y')
xlabel('Holding period in months')
ylabel('Annualized Sharpe ratio')
set(gca,'FontSize',8)
axis([1 36 -0.2 0.65]); 
xticks([1 6 12 18 24 30 36])

